<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="books.storage.service.*"%>
<%@ page import="books.borrowing.entity.*"%>
<%@ page import="java.util.List"%>
<%@ page import="books.storage.service.*"%>
<%@ page import="books.borrowing.entity.*"%>
<%@ page import="books.borrowing.bo.*"%>
<%@ page import="books.borrowing.*"%>
<%@ page import="java.util.ArrayList"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type"
	content="text/html; charset=windows-1252" />
<title>ELibrary - Empruntez un ou des livres</title></title>
<link rel="stylesheet" type="text/css" href="style.css" />

</head>
<body>
	<div id="wrap">

		<div class="header">
			<div class="logo">
				<a href="Elibrary"><img src="images/logo.gif" alt="" title=""
					border="0" /></a>
			</div>
			<div id="menu">
				<ul>
					<li><a href="/ELibrary">Accueil</a></li>
					<li><a href="/ELibrary/catalog">Consulter le catalogue</a></li>
					<% 
					SubscriberEntity user = (SubscriberEntity) session
					.getAttribute("user");
					if(user!=null) {
						out.println("<li class='selected'><a href='/ELibrary/rent'>Voir mes emprunts</a></li>");
						out.println("<li><a href='/ELibrary/edit_profile'>Modifier mon profil</a></li>");
					}
					%>
				</ul>
			</div>
		</div>


		<div class="center_content">
			<div class="left_content">
				<center>
					<h2>La liste de mes emprunts</h2>
				</center>
				<%
					if (user == null) {
						out.println("<p style='color:red;>Vous devez être connecté pour afficher cette page</p>");
					}
					List<BookBorrowingEntity> booksBorrowed = new ArrayList<BookBorrowingEntity>();
					if (session.getAttribute("books_borrowed") != null) {
						booksBorrowed = (List<BookBorrowingEntity>) session
								.getAttribute("books_borrowed");
						for (BookBorrowingEntity bookB : booksBorrowed) {
							IBookManagerClientService bookManager = EJBFacade
									.getBooksManager();
							BookDto book = bookManager.findBook(bookB.getBookISBN());

							String css_class = (bookB.getReturnDate() != null) ? "new_prod_box_returned"
									: "new_prod_box";
							out.println("<div class='" + css_class + "'>");
							out.println("<a href='#'>" + book.getTitle() + "<br/>par "
									+ book.getAuthor().getName() + "</a>");
							out.println("<div class='new_prod_bg'>");
							out.println("<a><img border='0' class='thumb' title='' alt='' src='images/books/"
									+ book.getIsbn() + ".jpg'></a>");
							if (user != null) {
								String rent_phrase = (bookB.getReturnDate() != null) ? "Rendu le "
										+ bookB.getReturnDate()
										: "Emprunté le : " + bookB.getRentDate();
								out.println("<p style='font-weight:bold;'>"
										+ rent_phrase + "</p>");
								out.println("<form method='post' action='rent'>");
								out.println("<input type='hidden' name='user_action' value='rent_back' />");
								out.println("<input type='hidden' name='book_isbn' value='"
										+ book.getIsbn() + "' />");
								out.println("<input type='hidden' name='user_login' value='"
										+ user.getLogin() + "' />");
								if (bookB.getReturnDate() == null) {
									out.println("<input type='submit' value='Rendre ce livre'>");
								}
								out.println("</form>");
							}
							out.println("</div>");
							out.println("</div>");
						}
					}
				%>



				<div class="clear"></div>
			</div>
			<!--end of left content-->

			<div class="right_content">

				<div class="right_box">

					<jsp:include page="login_form.jsp" />
				</div>


			</div>
			<div class="clear"></div>
		</div>
		<!--end of center content-->
		<div class="footer">
			<div class="left_footer">
				<img src="images/footer_logo.gif" alt="" title="" /><br />
			</div>
			<div class="right_footer">
				<a href="#">Accueil</a>

			</div>
		</div>
	</div>
</body>
</html>